home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CLASSSRC.PAK / COLOR.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  179 lines

  1. //----------------------------------------------------------------------------
  2. // Borland WinSys Library
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   5.14  $
  6. //
  7. // Implementation of color classes
  8. //----------------------------------------------------------------------------
  9. #include <winsys/pch.h>
  10. #include <winsys/color.h>
  11. #include <winsys/system.h>
  12.  
  13. // Few constants only defined when WINVER >= 0x0400
  14. //
  15. #if !defined(COLOR_3DDKSHADOW)
  16. # define COLOR_3DDKSHADOW        21
  17. #endif
  18. #if !defined(COLOR_3DLIGHT)
  19. # define COLOR_3DLIGHT           22
  20. #endif
  21. #if !defined(COLOR_INFOTEXT)
  22. # define COLOR_INFOTEXT          23
  23. #endif
  24. #if !defined(COLOR_INFOBK)
  25. # define COLOR_INFOBK            24
  26. #endif
  27.  
  28. static bool
  29. isWin31()
  30. {
  31. #if   defined(BI_PLAT_WIN16)
  32.   return !TSystem::IsWin95() && !TSystem::IsWoW();
  33. #elif defined(BI_PLAT_WIN32)
  34.   return !TSystem::IsWin95() && !TSystem::IsNT();
  35. #else
  36.   return false;
  37. #endif
  38. }
  39.  
  40. const TColor TColor::Black(0, 0, 0);         // 0
  41. const TColor TColor::LtGray(192, 192, 192);  // 7
  42. const TColor TColor::Gray(128, 128, 128);    // 8
  43. const TColor TColor::LtRed(255, 0, 0);       // 9
  44. const TColor TColor::LtGreen(0, 255, 0);     // 10
  45. const TColor TColor::LtYellow(255, 255, 0);  // 11
  46. const TColor TColor::LtBlue(0, 0, 255);      // 12
  47. const TColor TColor::LtMagenta(255, 0, 255); // 13
  48. const TColor TColor::LtCyan(0, 255, 255);    // 14
  49. const TColor TColor::White(255, 255, 255);   // 15
  50.  
  51. //
  52. // Special marker colors using flag bit pattern. Value never really used.
  53. // Value must not change for streaming compatibility w/ OWL's TWindow
  54. //
  55. const TColor TColor::None(0xFF000000l);
  56. const TColor TColor::Transparent(0xFE000000l);
  57.  
  58. //
  59. // Symbolic system colors looked up on evaluation or conversion
  60. //
  61. #define Symbolic 0x80000000UL
  62. const TColor TColor::SysScrollbar          (Symbolic | COLOR_SCROLLBAR);
  63. const TColor TColor::SysDesktop            (Symbolic | COLOR_BACKGROUND);
  64. const TColor TColor::SysActiveCaption      (Symbolic | COLOR_ACTIVECAPTION);
  65. const TColor TColor::SysInactiveCaption    (Symbolic | COLOR_INACTIVECAPTION);
  66. const TColor TColor::SysMenu               (Symbolic | COLOR_MENU);
  67. const TColor TColor::SysWindow             (Symbolic | COLOR_WINDOW);
  68. const TColor TColor::SysWindowFrame        (Symbolic | COLOR_WINDOWFRAME);
  69. const TColor TColor::SysMenuText           (Symbolic | COLOR_MENUTEXT);
  70. const TColor TColor::SysWindowText         (Symbolic | COLOR_WINDOWTEXT);
  71. const TColor TColor::SysCaptionText        (Symbolic | COLOR_CAPTIONTEXT);
  72. const TColor TColor::SysActiveBorder       (Symbolic | COLOR_ACTIVEBORDER);
  73. const TColor TColor::SysInactiveBorder     (Symbolic | COLOR_INACTIVEBORDER);
  74. const TColor TColor::SysAppWorkspace       (Symbolic | COLOR_APPWORKSPACE);
  75. const TColor TColor::SysHighlight          (Symbolic | COLOR_HIGHLIGHT);
  76. const TColor TColor::SysHighlightText      (Symbolic | COLOR_HIGHLIGHTTEXT);
  77. const TColor TColor::Sys3dFace             (Symbolic | COLOR_BTNFACE);
  78. const TColor TColor::Sys3dShadow           (Symbolic | COLOR_BTNSHADOW);
  79. const TColor TColor::SysGrayText           (Symbolic | COLOR_GRAYTEXT);
  80. const TColor TColor::SysBtnText            (Symbolic | COLOR_BTNTEXT);
  81.  
  82. // NOTE: WINVER >= 0x030a
  83. //
  84. const TColor TColor::SysInactiveCaptionText(Symbolic | COLOR_INACTIVECAPTIONTEXT);
  85. const TColor TColor::Sys3dHilight          (Symbolic | COLOR_BTNHIGHLIGHT);
  86.  
  87. // NOTE: WINVER >= 0x0400
  88. //
  89. const TColor TColor::Sys3dDkShadow(isWin31() ? (Symbolic | COLOR_WINDOWFRAME) :
  90.                                                (Symbolic | COLOR_3DDKSHADOW));
  91. const TColor TColor::Sys3dLight   (isWin31() ? (Symbolic | COLOR_BTNFACE) :
  92.                                                (Symbolic | COLOR_3DLIGHT));
  93. const TColor TColor::SysInfoText  (isWin31() ?  MkRGB(0,0,0) :
  94.                                                (Symbolic | COLOR_INFOTEXT));
  95. const TColor TColor::SysInfoBk    (isWin31() ?  MkRGB(255,255,128) :
  96.                                                (Symbolic | COLOR_INFOBK));
  97.  
  98. #if defined(BI_NAMESPACE)
  99. namespace ClassLib {
  100. #endif
  101.  
  102. //
  103. // Convert a bit count into a color count for color table use, verifying that
  104. // the bit count is one that is supported by Windows, ie 1, 4, 8, 16, 24, 32.
  105. //
  106. // If the bit count is not supported, -1 is returned.
  107. //
  108. long _WSYSFUNC
  109. NColors(uint16 bitCount)
  110. {
  111.   if (bitCount == 1 || bitCount == 4 || bitCount == 8)
  112.     return 1 << bitCount;
  113.   if (bitCount == 16 || bitCount == 24 || bitCount == 32)
  114.     return 0;
  115.   return -1;
  116. }
  117.  
  118. //
  119. // Return the number of bits required to represent a given number of colors
  120. //
  121. uint16 _WSYSFUNC
  122. NBits(long colors)
  123. {
  124.   if (colors <= 2)
  125.     return 1;
  126.   if (colors <= 16)
  127.     return 4;
  128.   if (colors <= 256)
  129.     return 8;
  130.   if (colors <= 65536L)
  131.     return 16;
  132.   return 24;
  133. }
  134.  
  135. #if defined(BI_NAMESPACE)
  136. } // namespace ClassLib
  137. #endif
  138.  
  139. //
  140. // Get a 32bit COLORREF type from this color object. Performs a
  141. // GetSysColor() lookup if the object represents a symbolic sys-color index.
  142. //
  143. COLORREF
  144. TColor::GetValue() const
  145. {
  146. #if defined(BI_PLAT_MSW)
  147.   return IsSysColor() ? ::GetSysColor(Index()) : Value;
  148. #else
  149.   return Value;
  150. #endif
  151. }
  152.  
  153. //
  154. // Return the color's red component
  155. //
  156. uint8
  157. TColor::Red() const
  158. {
  159.   return (uint8)(uint16)GetValue();
  160. }
  161.  
  162. //
  163. // Return the color's green component
  164. //
  165. uint8
  166. TColor::Green() const
  167. {
  168.   return (uint8)(uint16)(((uint16)GetValue()) >> 8);
  169. }
  170.  
  171. //
  172. // Return the color's blue component
  173. //
  174. uint8
  175. TColor::Blue() const
  176. {
  177.   return (uint8)(uint16)(GetValue()>>16);
  178. }
  179.